package {
	import cn.flashk.CustomItem;
	import cn.flashk.CustomTreeRender;
	import cn.flashk.controls.Alert;
	import cn.flashk.controls.Button;
	import cn.flashk.controls.CheckBox;
	import cn.flashk.controls.ComboBox;
	import cn.flashk.controls.DataGrid;
	import cn.flashk.controls.Label;
	import cn.flashk.controls.List;
	import cn.flashk.controls.ProgressBar;
	import cn.flashk.controls.RadioButton;
	import cn.flashk.controls.ScrollPane;
	import cn.flashk.controls.TabBar;
	import cn.flashk.controls.TabNav;
	import cn.flashk.controls.TextArea;
	import cn.flashk.controls.TextInput;
	import cn.flashk.controls.TileList;
	import cn.flashk.controls.Tree;
	import cn.flashk.controls.data.CustomListIVo;
	import cn.flashk.controls.data.DataProvider;
	import cn.flashk.controls.events.ListEvent;
	import cn.flashk.controls.managers.SkinLoader;
	import cn.flashk.controls.managers.SkinThemeColor;
	import cn.flashk.ui.UI;
	
	import com._public._net.LoadData;
	import com.flashdynamix.utils.SWFProfiler;
	import com.flashdynamix.utils.Util;
	import com.skins.MkConfig;
	import com.skins.Skin;
	
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	
	[SWF(frameRate = "30" , width = "1000" , height = "600" , backgroundColor = "0xffffff")]
	public class FlashK extends Sprite{
		private var _bd:BitmapData;
		private var dg:DataGrid;
		private var _list:List;
		private var _label2:Label;
		
		public function FlashK() {
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			SWFProfiler.init(stage,this);
			UI.init(this.stage);			//舞台颜色不一样
			SkinThemeColor.userDefaultColor(7);
			/*var btn:Button = UI.creatButton("Button",this);
			btn.name = "btn";
			var label:Label = new Label();
			label.text = "Label";
			UI.buildOne("btn",this,label);*/
			
			_bd = new BitmapData(14, 14, true, 0x00FFFFFF);
			_bd.setPixel32(5, 5, 0xFF000000);
			_bd.setPixel32(7, 7, 0xFF000000);
			_bd.setPixel32(5, 7, 0xFF000000);
			_bd.setPixel32(5, 9, 0xFF000000);
			_bd.setPixel32(12, 5, 0xFFFF6600);
			_bd.setPixel32(12, 7, 0xFF00FF00);
			_bd.setPixel32(10, 7, 0xFF0000FF);
			_bd.setPixel32(12, 9, 0xFF000000);
			
			SkinLoader.loadSkinFile("skin/assert/skin.swf");
			SkinLoader.eventDispatcher.addEventListener(SkinLoader.SKIN_LOADED,startBtn)
			//startBtn();
		}
		protected function startBtn(event:Event=null):void {
			LoadData.getInstance().loadXML("skin/style.xml",handler0);
			//加载样式设置
			function handler0(val:XML):void{
				SkinLoader.setSkinStyle(val); //设置按钮样式
				MkConfig.getInstance().skinConfig="skin/skinConfig.xml"
				MkConfig.getInstance().addEventListener(Event.COMPLETE, panelInit);//listDisplay
			}
		}
		
		protected function dataGridHandler(event:Event):void {
			var dg:DataGrid = new DataGrid();
			dg.setSize(440,382);
			addChild(dg);
			dg.labels = ["ID","状态","时间","值","对象"];
			dg.dataField = ["id","type","time","value"];
			for(var i:int=0;i<12;i++) {
				var obj:Object = {};
				obj.id = i+1;
				obj.type = "type"+i;
				obj.value = "value";
				obj.time = Util.getSysDate(new Date().getTime());
				dg.addItem(obj);
			}
		}
		
		private var _pro1:ProgressBar;
		protected function progressBar(event:Event):void {
			_pro1 = new ProgressBar();
			_pro1.setSize(242,21);
			addChild(_pro1)
			this.addEventListener(Event.ENTER_FRAME, updateProgress);
			
			var label:Label = new Label();
			label.text = "Label";
			label.moveTo(_pro1.width + 10,0);
			addChild(label);
			
			var btn:Button = new Button("button");
			btn.setSize(368,58);
			btn.moveTo(label.x,label.height + 10);
			btn.label = "button";
			btn.txtForamt = Skin.librarys.getTextFormat("t22_ffffff");
			addChild(btn);
			
//			return;
			var tabnav:TabNav = new TabNav("tabnav");
			tabnav.moveTo(0,120);
			tabnav.setSize(240,180);
			var sp1:Sprite= new Sprite();
			var sp2:Sprite= new Sprite();
			var sp3:Sprite= new Sprite();
			tabnav.addTab("选项一",sp1);
			tabnav.addTab("选项二",sp2);
			tabnav.addTab("选项三",sp3);
			addChild(tabnav);
			
			var tabBar:TabBar = new TabBar();
			tabBar.moveTo(tabnav.width + 20,tabnav.y);
			sp1= new Sprite();
			sp2= new Sprite();
			sp3= new Sprite();
			tabBar.addTab("选项一",sp1,_bd,true);
			tabBar.addTab("选项二",sp2,_bd,true);
			addChild(tabBar);
			
		}
		
		/**
		 * 进度条数据
		 * @param event
		 */	
		private var _pcount:int = 0;
		protected function updateProgress(event:Event):void {
			_pcount++;
			_pro1.value = _pcount / 100;
			if (_pcount > 1050){
				_pcount = 0;
			}
		}
		
		private function scroll(e:Event):void{
			var label:Label = new Label();
			label.textFormat = Skin.librarys.getTextFormat("t14_ff0000")
			addChild(label)
			label.text = "文本";
			
			var input:TextInput = new TextInput("input");
			input.y = label.height + 4;
			input.tipText = "请输入内容"
			addChild(input);
			
			var area:TextArea = new TextArea("textArea");
			area.text = "文本框"
			addChild(area);
			area.y = input.height + input.y + 6;
			
			var spri:Sprite = new Sprite;
			addChild(spri)
			spri.x = area.width + 10;
			spri.y = area.y;
			
			var radio:RadioButton = new RadioButton("radio");
			spri.addChild(radio);
			var radio1:RadioButton = new RadioButton("radio");
			radio1.y = 60;
			spri.addChild(radio1);
			
			var check:CheckBox = new CheckBox("check");
			check.y = 120;
			spri.addChild(check);
			
		}
		
		protected function panelInit(event:Event=null):void {
			//ToolTip.hideBg();
			/*var bg:Sprite = new Sprite();
			RoundRectAdvancedDraw.drawRect(bg.graphics,90,240);
			addChild(bg);
			var vscrollBar:VScrollBar = new VScrollBar("scroll");
			addChild(vscrollBar);
			vscrollBar.setTarget(bg,true,90,240);
			vscrollBar.updateSize(bg.height);
			vscrollBar.x = 90;
			vscrollBar.height = 240;
			return;*/
			/*var spa:ScrollList = new ScrollList();
			spa.load(new URLRequest("skin/assert/1.png"));
			spa.setSize(958,257);
			this.addChild(spa);
			spa.x = spa.y = 0;
			trace(spa.width,spa.height);
			var label:Label = new Label();
			label.text = "Label";
			label.moveTo(spa.width,spa.height);
			addChild(label);
			this.addEventListener(MouseEvent.CLICK,ahandler);*/
			var loader:Loader = new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,resizeHandler);
			loader.load(new URLRequest("skin/assert/2.png"));
		}
		
		protected var spa:ScrollPane
		protected function resizeHandler(event:Event):void {
			spa = new ScrollPane();
			spa.setSize(977,257);
			spa.addView(event.target.content);
			this.addChild(spa);
			spa.x = spa.y = 0;
			
			//this.addEventListener(MouseEvent.CLICK,ahandler);
		}
		
		protected function ahandler(event:MouseEvent):void {
			spa.setSize(950,294);
		}
		protected function btnHandler(event:ListEvent):void {
			
		}
		
		protected function styleInit(event:Event=null):void {
			var label:Label = new Label();
			label.textFormat = Skin.librarys.getTextFormat("t18_ff0000");
			label.text = "请输入内容";
			addChild(label);
			
			var input:TextInput = new TextInput();
			input.height = 32;
			input.textFormat = Skin.librarys.getTextFormat("t18_ff0000");
			input.tipText = "请输入内容";
			input.moveTo(0,label.height);
			addChild(input);
			
			var check:CheckBox = new CheckBox("check");
			check.moveTo(0,input.height + input.y + 10);
			addChild(check);
			
			var radio:RadioButton = new RadioButton();
			radio.moveTo(0,check.height + check.y + 8);
			radio.textFormat(Skin.librarys.getTextFormat("radio", "upTxt"))
			addChild(radio);
			var radio1:RadioButton = new RadioButton();
			radio1.moveTo(0,radio.y + radio.height);
			addChild(radio1);
		}
		
		protected function handler00(event:Event=null):void {
			trace("值:" + event.target.value);
		}
		
		protected function listDisplay(event:Event=null):void {
			var dp:DataProvider = new DataProvider([1,2,3,4,5,6,7,8,9,10]);
			var list:List = new List();
			list.itemRender = CustomItem;
			list.dataProvider = dp;
			list.setSize(120,184)
			list.moveTo(486,0);
			addChild(list);
			list.addEventListener(Event.CHANGE,handler1)
			
			var tileList:TileList = new TileList("list");
			addChild(tileList);
			tileList.setSize(425,228);
			/*tileList.horizontalSpace = 0;
			tileList.verticalSpace = 0;*/
			tileList.itemRender = CustomItem;
			var item:CustomListIVo;
			for(var i:int=1;i<8;i++){
				item = new CustomListIVo()
				item.label ="文件"+i;
				item.source= "skin/assert/alpha.png";
				tileList.addItem(item)
			}
			tileList.addEventListener(Event.CHANGE,handler);
			
			var combox:ComboBox = new ComboBox("comboBox");
			combox.editable = true;
			combox.dataProvider = dp;
			combox.moveTo(1,tileList.height + 4);
			addChild(combox);
			
			var btn:Button = new Button();
			btn.label = "button";
			addChild(btn);
			
			var dg:DataGrid = new DataGrid("dataGrid");
			dg.setSize(480,214);
			addChild(dg);
			dg.moveTo(10,combox.height + combox.y + 10);
			dg.labels = ["ID","状态","时间","值","对象"];
			dg.dataField = ["id","type","time","value"];
			for(i=0;i<6;i++) {
				var obj:Object = {};
				obj.id = i+1;
				obj.type = "type"+i;
				obj.value = "value";
				obj.time = Util.getSysDate(new Date().getTime());
				dg.addItem(obj);
			}
			
			var tree:Tree = new Tree();
			tree.moveTo(list.x + list.width + 20,0)
			tree.itemDoubleClickEnabled = true;
			tree.addEventListener(ListEvent.ITEM_DOUBLE_CLICK,onDoubleClick);
			tree.addEventListener(ListEvent.ITEM_CLICK,onItemClick);
			tree.itemRender = CustomTreeRender;
			//tree.itemRender = BaseTreeItemRender;
			tree.isParentAutoClickOpen = true;
			tree.setSize(240,260);
			var _xml:XML = <data>
				<item label="房间" id="1">
					<item label="女" id="1">
						<item label="aaa1"  id="51"/>
						<item label="aaa2"  id="51"/>
						<item label="aaa3"  id="51"/>
						<item label="aaa4"  id="51">
							<item label="bbb1"  id="51"/>
							<item label="bbb2"  id="51"/>
							<item label="bbb3"  id="51"/>
							<item label="bbb4"  id="51"/>
						</item>
					</item>
					<item label="男" id="1">
						<item label="bbb1"  id="51"/>
						<item label="bbb2"  id="51"/>
						<item label="bbb3"  id="51"/>
						<item label="bbb4"  id="51"/>
						<item label="bbb5"  id="51"/>
						<item label="bbb6"  id="51"/>
					</item>
				</item>
				<item label="我的好友" id="1">
					<item label="玩家a"  id="51"/>
				</item>
				<item label="陌生人" id="1">
					<item label="玩家b"  id="51"/>
				</item>
				<item label="黑名单" id="1">
					<item label="玩家c"  id="51"/>
				</item>
				</data>
				
			addChild(tree);
			tree.dataProvider = _xml;
			
			_label2 = new Label();
			_label2.text = "用户单击项目：";
			addChild(_label2);
			_label2.moveTo(tree.x,tree.height + 10);
		}
		
		protected function handler(event:Event):void {
			var tileList:TileList = event.target as TileList;
			trace(tileList.selectedItem.source)
		}		
		protected function handler1(event:Event):void {
			var list:List = event.target as List;
			trace(list.selectedItem.label)
		}		
		
		protected function onDoubleClick(event:ListEvent):void {
			Alert.show("用户双击项目："+ event.targetItem.data.@label);
		}
		
		protected function onItemClick(event:ListEvent):void {
			_label2.text = "用户单击项目："+ event.targetItem.data.@label;
		}
	}
}